package com.study.config;

import com.study.constant.CommonKeys;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * @author CSDN 流放深圳
 * @description 项目启动后，在目录下创建文件夹
 * @create 2024-04-13 15:55
 * @since 1.0.0
 */
@Component
public class DirectoryInitializer {

    private static Logger log = LoggerFactory.getLogger(DirectoryInitializer.class);

    /**
     * 在根目录下创建文件夹，用来存储授权证书文件
     */
    @PostConstruct
    public void init() {
        Path directory = Paths.get(CommonKeys.CERTIFICATE_DIRECTORY);
        try {
            Files.createDirectories(directory);
        } catch (IOException e) {
            log.error(e.getMessage(), e);
        }
    }
}
